import java.util.List;

public class LinkedListStack <E> implements Stack<E> {

    private DummyHeadLinkedList<E> list;

    public LinkedListStack(){
        list  = new DummyHeadLinkedList<>();
    }

    @Override
    public int getSize(){
        return list.getSize();
    }

    @Override
    public boolean isEmpty(){
        return list.isEmpty();
    }

    @Override
    public void push(E e) throws Exception {
        list.addFirst(e);
    }

    @Override
    public E pop(){
        return (E) list.removeFirst();
    }

    @Override
    public E peek(){
        return list.getFirst();
    }
    @Override
    public String toString(){
        StringBuilder builder = new StringBuilder();
        builder.append("stack tpo :");
        builder.append(list);
        return builder.toString();
    }

    public static void main(String[] args) throws Exception {
        LinkedListStack<Integer> linkedListStack = new LinkedListStack<>();
        for (int i = 0; i < 10; i++) {
            linkedListStack.push(i);
        }
        System.out.println(linkedListStack);

        Integer peek = linkedListStack.peek();
        System.out.println("peek :"+peek);
    }

}
